package com.zhongcw.test.spring.boot.swagger2.employee.controller;

import com.zhongcw.test.spring.boot.swagger2.pojp.Employee;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 员工控制器
 *
 * @author ZCW
 * @createTime 2018/3/28
 * @lastUpdateTime 2018/3/28 ZCW
 */
@RestController
@RequestMapping("/employees")
public class EmployeeController {
    private static final Map<String, Employee> employees = Collections.synchronizedMap(new HashMap<String, Employee>());

    static {
        employees.put("emp1",new Employee("emp1"));
        employees.put("emp2",new Employee("emp2"));
    }

    @GetMapping
    public List<Employee> getEmployees() {
        return new ArrayList<>(employees.values());
    }

    @GetMapping("/{empName}")
    public Employee getEmployees(String empName){
        return  employees.get(empName);
    }

    @PostMapping
    public boolean addEmployees(Employee employee){
        employees.put(employee.getName(),employee);
        return true;
    }

}

